package com.ntd.study.protocol.emq.core;

import ntd.util.UtilLog;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;

/**
 * @author liuwenju
 * @date 2021/4/15
 */
public class NtdMqttOnMsg implements MqttCallback {

    public void connectionLost(Throwable cause) {
        // 连接丢失后，一般在这里面进行重连
        UtilLog.info("连接断开，可以做重连");
    }

    public void messageArrived(String topic, MqttMessage message) throws Exception {
        // subscribe后得到的消息会执行到这里面
        UtilLog.info("接收消息主题:" + topic);
        UtilLog.info("接收消息Qos:" + message.getQos());
        UtilLog.info("接收消息内容:" + new String(message.getPayload()));
    }

    public void deliveryComplete(IMqttDeliveryToken token) {
        UtilLog.info("deliveryComplete---------" + token.isComplete());
    }
}
